import { _decorator, bezier, Component, Label, Node, Sprite, SpriteFrame, sys } from 'cc';
import { MyButton } from './commonComp/MyButton';
import { HttpCom } from './net/HttpCom';
const { ccclass, property } = _decorator;

@ccclass('TaskItem')
export class TaskItem extends Component {

    @property([SpriteFrame])
    channelIconSf: SpriteFrame[] = []
    @property([SpriteFrame])
    rewardIconSf: SpriteFrame[] = []
    @property(Sprite)
    channelIconSp: Sprite = null;
    @property(Sprite)
    rewardIconSp: Sprite = null;
    @property(Label)
    infoLab: Label = null;
    @property(Label)
    rewardLab: Label = null;

    @property(Node)
    finishedIcon: Node = null;

    @property(MyButton)
    taskBtn: MyButton = null;

    
    taskId: number = 0;
    
    start() {
        
    }

    initView(iconId: number, info: string, rewardIconId: number,rewardInfo: any,taskId: number){
        this.taskId = taskId;
        this.channelIconSp.spriteFrame = this.channelIconSf[iconId];

        switch(info){
            case "addTgChannel": 
            this.infoLab.string =  "Join our TG channel"
                break;
            case "addX": 
            this.infoLab.string =  "Follow on Twitter(X)"
                break;
            case "likeX":
            this.infoLab.string =  "Like on Twitter(X)"
            
                break;
            case "GooseAgentX":
            this.infoLab.string =  "Follow Goose Agent"
            
                break;
            case "GooseAgentGame":
            this.infoLab.string =  "Launch Goose Agent"
            
                break;
            case "FrogsX":
            this.infoLab.string =  "Follow FROGS Twitter"
            
                break;
            case "FrogsGame":
            this.infoLab.string =  "Play FROGS game"
            
                break;
            case "MonstersGame":
            this.infoLab.string =  "Play Cat VS Monsters"
            
                break;
            case "hangarxgamingGame":
            this.infoLab.string =  "Play HangarX’s"
            
                break;
            // default :
            //     this.infoLab.string = info
        }
        

        this.rewardIconSp.spriteFrame = this.rewardIconSf[rewardIconId]

        this.rewardLab.string = rewardInfo.value;


    }

    onTaskBtnClick(){
        console.log(this.taskId);
        switch(this.taskId){
            case 1:
                HttpCom.addTgChannel()
                sys.openURL("https://t.me/LastOasisChannel");
                break;
            case 3:
                sys.openURL("https://x.com/LastOasisTon");
                HttpCom.addX()
                break;
            case 6:
                sys.openURL("https://x.com/LastOasisTon");
                HttpCom.likeX(this.taskId)
                break;



            //新增任务
            case 7:
                sys.openURL("https://x.com/goose_agent");
                HttpCom.doTask(this.taskId)
                break;
            case 8:
                sys.openURL("https://t.me/goose_agent_bot/gooseagent?startapp=RTFzNkYxcG4ycW5CM1B6cTgyVlRBQT09");
                HttpCom.doTask(this.taskId)
                break;
            case 9:
                sys.openURL("https://x.com/realFrogsClub");
                HttpCom.doTask(this.taskId)
                break;
            case 10:
                sys.openURL(" https://t.me/realFrogs_bot");
                HttpCom.doTask(this.taskId)
                break;
            case 11:
                sys.openURL("https://t.me/cat_vs_monsters_bot?start=1367612412");
                HttpCom.doTask(this.taskId)
                break;
            case 12:
                sys.openURL("https://t.me/hangarxgaming_bot/hangarxgaming?startapp=LastOasisTON");
                HttpCom.doTask(this.taskId)
                break;
            
            
        }
    }

    changeFineshState(state: boolean){
        this.taskBtn.interactable = !state;
        this.finishedIcon.active = state;
        this.taskBtn.node.getComponent(Sprite).grayscale = state;
    }

    update(deltaTime: number) {
        
    }
}


